//
//  NearByController.m
//  QSBK
//
//  Created by Eric Wang on 4/17/15.
//  Copyright (c) 2015 Eric Wang. All rights reserved.
//
#import "GameCenter.h"
#import "Common.h"
#import "NearByController.h"
#import "NearBy.h"
#import "NearByCell.h"
@interface NearByController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *nearByArray;
@end

@implementation NearByController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self data];
    [self addTableView];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)addTableView
{
    
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.scrollEnabled = NO;
    [self.view addSubview:self.tableView];
}

#pragma tableview delegate datdasource 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NearByCell *cell = [[NearByCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    if(indexPath.section == 0)
    {
        cell.nearBy=self.nearByArray[indexPath.row];
    }else{
        cell.nearBy= self.nearByArray[indexPath.row+indexPath.section*3];
    }
    
    return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section ==0 && indexPath.row == 2)
    {
        if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(presentToNearByController)])
        {
            [self.delegate presentToNearByController];
        }
    }else if(indexPath.section==0 && indexPath.row == 0)
    {
        if(self.delegate!=nil&&[self.delegate respondsToSelector:@selector(presentToNearPeoPleController)])
        {
            [self.delegate presentToNearPeoPleController];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (ScreenH-StatusBarH-60)/6;
}

#pragma datasource
-(void)data
{
    self.nearByArray = [[NSMutableArray alloc]init];
    NSArray *imageArray = [NSArray arrayWithObjects:@"found_ic_nearby",@"found_ic_store.png",@"found_ic_game.png",@"found_ic_cafe.png",@"icon_jzdd.png",@"icon_mrdb.png", nil];
    NSArray *titleArray = [NSArray arrayWithObjects:@"附近",@"糗百货",@"游戏",@"里屋",@"机制大帝",@"每日嘚吧", nil];
    NSArray *detailArray = [NSArray arrayWithObjects:@"Hey,来看看周围的糗友吧",@"萌萌的糗事百科周边，买买买",@"精选好玩游戏汇总",@"糗百逗比集中营",@"不进来不知道自己智商有多高",@"在这里你只能说一句话", nil];
    
    for(int i=0;i<6;i++){
        NearBy *nearBy = [[NearBy alloc]init];
        nearBy.imageName = imageArray[i];
        nearBy.title = titleArray[i];
        nearBy.detail = detailArray[i];
        [self.nearByArray addObject:nearBy];
    }
}

@end
